home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Replace all occurances of an old substring with a new substring. E.g.:
- ** x = 'foo.txt'
- ** x = 'rename' x replace( x, '.txt', '.text' )
- ** say x
- ** ==> rename foo.txt foo.text
- **
- ** NOTES:
- ** It _IS_ safe to do:
- ** say replace( 'abc', 'b', 'bb' )
- ** ==> abbc
- **
- ** I.e., it does not get caught in infinite loops. (^&
- **
- */
- parse arg src, old, new
- str = ''
- do while '' ~= src
- loc = pos( old, src )
- parse var src sub (old) src
- str = str || sub
- if loc ~= 0 then
- str = str || new
- end
- return str
-
-